<template>
  <div>
    <!--已签名金卡协议-->
    <p class="text" v-html="agreement"></p>
    <div v-if="isNeedEleSeal==0">
      <img width="100%" height="250px" :src="accountelesign.signStr" v-if="haveSign"/>
    </div>
    <div style="font-size: 14px" v-if="isNeedEleSeal==1">
      <p>甲方：{{companyName}}</p>
      <p>乙方（签署人）：<img width="120px" height="40px" style="padding-top: 10px" :src="accountelesign.signStr"
                      v-if="haveSign"/></p>
      <p style="padding-top: 30px">签订日期:{{signDate}}</p>
    </div>
    <div style="background-color: rgba(255, 255, 255, 255)" v-show="isNeedEleSeal==1">
      <canvas id="canvas" width="183" height="183" style="position: absolute;margin-top: -270px;transform: rotate(90deg); ">
      </canvas>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getAccountgoodsAgreement} from '../../../../test/unit/http'
  import {Toast} from 'we-vue'

  export default {
    name: 'havesignjinkaxieyi',
    props: {},
    data() {
      return {
        goods: {},
        haveSign: false,
        agreement: '',
        accountelesign: {},
        signDate: '',
        companyName: '',
        isNeedEleSeal: 0,
        eleSealImg: 0,
      };
    },
    methods: {
      getAccountgoodsAgreementData(params) {
        getAccountgoodsAgreement(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.agreement = res.object.agreement;
            this.haveSign = res.object.haveSign;
            if (this.haveSign) {
              this.accountelesign = res.object.accountelesign;
              let isNeedEleSeal = res.object.isNeedEleSeal;
              this.isNeedEleSeal = isNeedEleSeal
              if (isNeedEleSeal == 1) {
                let eleSealImg = res.object.eleSealImg;
                this.eleSealImg = res.object.eleSealImg;
                this.signDate = res.object.signDate;
                this.companyName = res.object.companyName;
                this.canvasYinZhang(eleSealImg)
              }
            }
          } else {
            Toast.fail(res.info);
          }
        })
      },
      canvasYinZhang(eleSealImg) {
        let canvas = document.getElementById("canvas");
        let cxt = canvas.getContext('2d')
        let imgScale = 0.6
        canvas.width = 200
        //创建新的图片对象
        let img = new Image();
        //指定图片的URL
        img.src = eleSealImg;
        //浏览器加载图片完毕后再绘制图片
        img.onload = function () {
          cxt.rotate(-20 * Math.PI / 180)
          cxt.clearRect(0, 0, canvas.width, canvas.height);
          cxt.drawImage(img, //规定要使用的图像、画布或视频。
            0, 0, //开始剪切的 x 坐标位置。
            img.width, img.height,  //被剪切图像的高度。
            0, 30,//在画布上放置图像的 x 、y坐标位置。
            img.width * imgScale, img.height * imgScale  //要使用的图像的宽度、高度
          )
        }
      },
    },
    created() {
      let accountGoodsId = this.$route.query.accountGoodsId;
      this.getAccountgoodsAgreementData({accountGoodsId: accountGoodsId});
    },
    mounted() {
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .divider {
    background-color: #eee;
    height: 20px;
    width: 100%;
    text-align: left;
    padding: 3px;

    .btn {
      button {
        color: #fff;
        border: none;
        width: calc(35% - 50px);
        margin-left: 30px;
      }

      :last-child {
        background-color: #f9964e;

      }

      :first-child {
        background-color: #ccc;
        margin-right: 20px;
      }
    }
  }

  .title {
    font-size: 20px;
    color: #111;
    font-weight: 700;
    padding: 10px;
  }

  .text {
    font-size: 15px;
    color: #666;
    line-height: 25px;
    text-indent: 30px;
    text-align: left;
    padding: -300px 10px 10px;
  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-image: linear-gradient(to right, #f9964e, #ff8551);
    height: 50px;
    line-height: 50px;
    color: #fff;
  }


</style>
